<?php
class pro_lap_data_mitra_aktif_model extends MY_Model {
	var $model = 'pro_lap_data_mitra_aktif';
	
	function GetJSON()
	{

		$ls_sql	= "	SELECT	*
					FROM	pro_mitra
					WHERE	UPPER(status_mitra) = 'MITRA AKTIF' AND
							(UPPER(kode_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(ktp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_toko_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_pemilik) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(alamat_lengkap) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_telp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_hand) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(status_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_kontrak) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(awal_kerja) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(akhir_kerja) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(fee_mitra) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_rekening) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_bank) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(atas_nama) LIKE '%".strtoupper(post('keyword'))."%')
							ORDER BY ".(post('sort')=='' ? 'kode_mitra' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('pro_mitra', $arr_data);
	}
		
	
	function Update($arr_data, $arr_rule){
		$this->db->update('pro_mitra', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_kode_mitra){
		$result = $this->db->get_where('pro_mitra', array('kode_mitra' => $as_kode_mitra));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_kode_mitra)
	{
		$result = $this->db->get_where('pro_mitra', array('kode_mitra' => $as_kode_mitra));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM pro_mitra WHERE kode_mitra = '".$arr_rule['kode_mitra']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['kode_mitra']."]<br />";
			}else{
				$this->db->delete('pro_mitra', array('kode_mitra' => $arr_rule['kode_mitra']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>